package com.servlet;

import com.entity.Book;
import com.entity.Users;
import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@WebServlet("/updataBook")
public class UpdataBookServlet extends HttpServlet {
    @Override
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Book book = new Book();
        book.setBookid(Long.parseLong(req.getParameter("bookid")));
        book.setBookname(req.getParameter("name"));
        book.setAuthor(req.getParameter("author"));
        book.setPublish(req.getParameter("publish"));
        book.setBookcount(Long.valueOf(req.getParameter("bookcount")));
        book.setBooktype(req.getParameter("booktype"));
        System.out.println("book.id:"+book.getBookid());
        req.setAttribute("book",book);
        req.getRequestDispatcher("/admin/add_book.jsp").forward(req,resp);
    }
}
